package info.androidhive.tabsswipe;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ActionsFragment extends Fragment{

	private String LOG_TAG = "___DEBUG_INFORM = ";
	private String[] numbers = {"one", "two", "three", "four", "five", "six", "seven"};
	private String[] colors = {"green", "yellow", "orange"};
	private ListView listView;
	private	ArrayAdapter<String> arrayAdapter;
	private int clickedPos = 0;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		final View rootView = inflater.inflate(R.layout.fragment_actions, container, false);

		arrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.list_view_row_patern, numbers);
		listView = (ListView) rootView.findViewById(R.id.listView);
		listView.setAdapter(arrayAdapter);
		listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> adapterView, View view, int pos, long id) {
				Toast.makeText(getActivity(),
					"clicked in item position " + pos + " , ID = " + id + ", " + adapterView.getAdapter().getItem(pos),
					Toast.LENGTH_SHORT).show();

//				if(pos == 0){
//					arrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.list_view_row_patern, colors);
//					listView = (ListView)rootView.findViewById(R.id.listView);
//					listView.setAdapter(arrayAdapter);
//					Log.d(LOG_TAG, "position == 0");
//				}

				if (pos == 0){
					setClickedPos(pos);
					chooser(rootView);
				}else if (pos == 1){
					setClickedPos(pos);
					chooser(rootView);
				}else if (pos == 2){
					setClickedPos(pos);
					chooser(rootView);
				}

			}
		});

		return rootView;
	}


	private void chooser(View rootView){
		if(getClickedPos() == 0){
			arrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.list_view_row_patern, colors);
			listView = (ListView)rootView.findViewById(R.id.listView);
			listView.setAdapter(arrayAdapter);
			Log.d(LOG_TAG, "position == 0");
		}else if(getClickedPos() == 1){

		}
	}


	public void setClickedPos(int clickedPos){
		this.clickedPos = clickedPos;
	}

	public int getClickedPos(){
		return clickedPos;
	}
}
